#include "InputLayoutManager.h"

#include <D3D10.h>

#include "D3DErrorChecker.h"
#include "EffectManager.h"
#include "LandWavesEffect.h"

namespace D3D10InputLayouts
{
    ID3D10InputLayout* InputLayoutManager::mLandWavesInputLayout = nullptr;

    void InputLayoutManager::initAll(ID3D10Device * const device)
    {
        initLandWavesInputLayout(device);
    }

    void InputLayoutManager::destroyAll()
    {
        mLandWavesInputLayout->Release();
    }

    void InputLayoutManager::initLandWavesInputLayout(ID3D10Device * const device)
    {
        D3D10_INPUT_ELEMENT_DESC vertexDesc[] = 
        {
            {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0},
            {"NORMAL",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
            {"TEXCOORD",  0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
        };

        D3D10_PASS_DESC PassDesc;
        ID3D10EffectTechnique* technique = D3D10Effects::EffectManager::mLandWavesEffect->mTechnique;
        technique->GetPassByIndex(0)->GetDesc(&PassDesc);
        HRESULT hr = device->CreateInputLayout(vertexDesc, 3, 
            PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &D3D10InputLayouts::InputLayoutManager::mLandWavesInputLayout);

        D3D10Utils::ErrorChecker(hr);
    }    
}

